var customerdata={}
var customerIds={}
//运营经理关联
function myFunction(tep){
    //销售经理
    if(tep==1){
        var manager=$("#sale_manager").val();
        var user_data = {
            param:manager,
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="0"){
                var jsonObj =data.data;
                if(jsonObj==""){
                    $("#tuan").html("<li>无数据</li> ");
                }else {
                    console.log(jsonObj)
                    var optionstring = "";
                    for (var  i= 0; i < jsonObj.length; i++) {
                        optionstring += "<li onclick='relation("+ jsonObj[i].user_id+",\""+jsonObj[i].user_name+"\")' data-align=\"" + jsonObj[i].user_name + "\" > " + jsonObj[i].user_name + "</li>";
                    }
                    $("#tuan").html(optionstring);
                }
            }else{
                $("#tuan").html("<li>无数据</li> ");
            }
        }
        web.doAjax(root.inter.getSaleManagerByParam,'post',user_data, succCallBack);
    }else {
        //运营经理
        var operate_manager=$("#operate_manager").val();
        var user_data = {
            keywords:operate_manager,
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="0"){
                var jsonObj =data.userList;
                if(jsonObj==""){
                    $("#tuan").html("<li>无数据</li> ");
                }else {
                    console.log(jsonObj)
                    var optionstring = "";
                    for (var  i= 0; i < jsonObj.length; i++) {
                        optionstring += "<li onclick='relation_x("+ jsonObj[i].USER_ID+",\""+jsonObj[i].NAME+"\")' data-align=\"" + jsonObj[i].ROLE_ID + "\" > " + jsonObj[i].NAME + "</li>";
                    }
                    $("#tuan_xiao").html(optionstring);
                }
            }else{
                $("#tuan_xiao").html("<li>无数据</li> ");
            }
        }
        web.doAjax(root.inter.getOperationManagerByParam,'post',user_data, succCallBack);
    }

}
//运营经理获取光标
$("#sale_manager").focus(function () {
    $("#tuan").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan").length == 0 && $(e.target).closest("#sale_manager").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan").hide()
    }
})
//销售经理获取光标
$("#operate_manager").focus(function () {
    $("#tuan_xiao").show()
});
$(document).bind("click",function(e){
    //id为menu的是菜单，id为open的是打开菜单的按钮
    if($(e.target).closest("#tuan_xiao").length == 0 && $(e.target).closest("#operate_manager").length == 0){
        //点击id为menu之外且id不是不是open，则触发
        $("#tuan_xiao").hide()
    }
})
function relation(id,ce) {
    $("#sale_manager").val(ce).text(id)
    $("#tuan").hide()
    console.log($("#sale_manager").text())
}
function relation_x(id,ce) {
    $("#operate_manager").val(ce).text(id)
    $("#tuan_xiao").hide()
    console.log($("#operate_manager").text())
}
//签约客户查询
function Customerquery() {
    //校验ID格式
    jQuery.validator.addMethod("confirmID",function(value, element){
        var returnVal = true;
        var cn = value.substring(0,2);
        var num = value.substring(2,10);
        if(!isNaN(num)&&cn=='CN'){
            returnVal = true;
        }
        else if(value==''){
            returnVal = true;
        }
        else{
            returnVal = false;
        }
        return returnVal;
    },"输入有误");         //验证错误信息

    $("#form-member").validate({
        rules: {
            kehu_id: {
                // maxlength:10,
                minlength:10,
                confirmID:$("#kehu_id").val(),
            },
            kehu_name: {
                // maxlength:30,
            },
            hetong: {
                // maxlength:10,
                // minlength:10,
            },
        },
        submitHandler:function(form){
            getList(1)
        }
    })
}
/*签约客户信息详情*/
function customerInfo(title, url) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
//签约客户详情
web.Customerdetails=(function(){
    return function(id){
        var customerCode =getQueryString('id');
            /*oldSysContractID=getQueryString("oldSysContractID"),
            contractID=getQueryString('contractID');*/
        var user_data = {
            customerCode:customerCode,
            /*oldSysContractID:oldSysContractID,
            contractID:contractID*/
            //01.01.2803
        }
        var succCallBack = function (data, status, response) {
            customerdata=data.customer.customerCode
            customerIds=data.customer.customer_id
            console.log(customerdata)
            console.log(customerIds)
            sessionStorage.setItem("customerdatas",customerdata);
            sessionStorage.setItem("customerid",data.customer.customer_id);
            sessionStorage.setItem("customertype",data.customer.customer_type);
            if(data.customer.customer_type=="商店"){
                $("#ceyuud").css({
                    display: "none"
                });

            }
            if(data.customer.customer_code=="05.02.0013"){
                $('#warehouseIdall').removeAttr('onclick');//去掉a标签中的onclick事件
                $("#warehouseIdall").attr("style", "color:#aaaaaa")
                $('#joinActivsityall').removeAttr('onclick');//去掉a标签中的onclick事件
                $("#joinActivsityall").attr("style", "color:#aaaaaa")

            }else {
                $('#warehouseIdall').attr('onclick','store_change()');
                $("#warehouseIdall").attr("style", "color:#1476e5;")
                $('#joinActivsityall').attr('onclick','updatafreight()');
                $("#joinActivsityall").attr("style", "color:#1476e5;")
            }
            /*$("#updaii").attr("onclick", 'updataii("' + data.memberCompanyInfo.member_id + '")');*/
            if(data.errorCode=="1") {
                var dataInter = data.customer,
                    project = data.projectList;

                var interText = doT.template($("#customerdetails_bob").text());
                $("#customerdetails_lsit").html(interText(dataInter));
                //项目
                var interText = doT.template($("#project_bob").text());
                $("#project_list").html(interText(project));
            }
            //权限控制函数
            power()
        };
        web.doAjax(root.inter.getSignCustomerDetailjhtml,'post',user_data, succCallBack);
    }
})();
//总包方详情
web.total=(function(){
    return function(id){
        var customerCode =getQueryString('customerCode'),
            belongProjectId=getQueryString("belongProjectId"),
            type=getQueryString('type'),
            contractorId=getQueryString('contractorId');
        var user_data = {
            customerCode:customerCode,
            contractorId:contractorId,
            belongProjectId:belongProjectId,
            type:type
        }
        var succCallBack = function (data, status, response) {
            console.log(data)
            if(data.errorCode=="1") {
                var dataInter = data.contractor;
                var interText = doT.template($("#total_bob").text());
                $("#total_list").html(interText(dataInter));
            }
        };
        web.doAjax(root.inter.getContractorByParam,'post',user_data, succCallBack);
    }
})();

//初始化客户归属下拉列表
function ascription() {
    var user_data = {
        organizationIds:sessionStorage.getItem("companya"),//销售归属权限串
       /* token: hex_md5(JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID +'xfs7Alc74oCVpHXg97etTs'),
        member_id:JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID*/
    }
    var succCallBack = function (data, status, response) {
        //console.log(data)
        if(data.errorCode=="0") {
            var dataInter=data.group;
            var interText = doT.template($("#ascription_bob").text());
            $("#ascription_lsit").html(interText(dataInter));
        }
    };
    return web.doAjax(root.inter.getGroup, 'post', user_data, succCallBack);
}
var dataSource = new Array();
var table;   //table对象
dataSource = [];
function orderList(data) {
    dataSource.splice(0, dataSource.length);//清空数组
    console.log(data)
    var datashu =data.list.startIndex+1;
    var result=data.list.result
    $.each(result, function (i, field) {
        var datashus = datashu++
        var rowData = new Array();
        rowData.push(field.customer_id);
        rowData.push(field.customer_name);
        rowData.push(field.customer_grade);
        rowData.push(field.belong_groupName);
        rowData.push(field.customer_type);
        rowData.push(field.independent_customer);
        rowData.push(field.customerSetup.warehouseName);
        rowData.push(field.customerSetup.limitType);
        rowData.push(field.is_restrict);
        rowData.push(field.invoice_basis);
        rowData.push(field.update_time);
        rowData.push(field.is_enter);
        rowData.push("操作");
        dataSource.push(rowData);
        rowData.push(datashus);
        rowData.push(field.customer_code);
        rowData.push(field.parent_customer_name);
        rowData.push(field.haveContract);
        rowData.push(field.parent_customer_code);
        rowData.push(field.parent_customer_id);
        rowData.push(field.customer_code);//客户代码
        rowData.push(field.forbidden);//状态
    });
    initDataTable(dataSource);
    function initDataTable(dataSource) {
        var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#datatable").DataTable({
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": false,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": [25, 5, 10, 50],
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
                "sProcessing": "<img src='./loading.gif' />"
            },
            data: dataSource,
            columnDefs: [
                {
                    "render": function (data, type, row, meta) {
                        var val = row[13]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        //客户代码
                        var val = row[19]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[3]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[4]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 6
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = ""
                        var names=""
                        if(row[15]==undefined){
                            names=""
                        }else {
                            names=row[15]
                        }
                        if (row[5] == 10) {
                            val = ''
                        }else {

                            if(row[17]==row[14] || row[17]==""){

                                    val = '该客户为主客户'

                            }else {

                                val='<a onclick="customerInfo(\'签约客户信息详情\',\'tomer_seeguanlian.html?id=' + row[17] +'&customerId=' + row[18] + '\')">'+names+'</a>'

                            }

                        }

                        return val;
                    },
                    "targets": 7
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[6]
                        if (val == undefined) {
                            val = ''
                        }
                        if(val ==""){
                            val = '平行仓'
                        }
                        return val;
                    },
                    "targets": 8
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = '';
                        var val1=""
                        if(row[7]==10){
                            val='不限制货到付款'
                        }else if(row[7]==20){
                            val='限制货到付款'
                        }
                        if(row[8]==1){
                            val1='限制发货'
                        }else if(row[8]==2){
                            val1='不限制发货'
                        }
                        return val+'<br>'+val1;
                    },
                    "targets": 9
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[9]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 10
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[10]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 11
                },

                {
                    "render": function (data, type, row, meta) {
                        var val=""
                       /* if (row[11] == 10) {
                            val = '<span class="dropDown"> <a class="dropDown_A powerButton 163" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">已入驻<i class="Hui-iconfont">&#xe6df;</i></a><ul class="dropDown-menu menu radius box-shadow"><li onclick="customer_wei(\'\',\'' + row[14] + '\')"><a href="#">未入驻</a></li></ul></span>';
                            return val;
                        } else if (row[11] == 20) {
                            val = '<span class="dropDown"> <a class="dropDown_A powerButton 163" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">未入驻<i class="Hui-iconfont">&#xe6df;</i></a><ul class="dropDown-menu menu radius box-shadow"><li onclick="customer_yi(\'\',\'' + row[14] + '\')"><a href="#">已入驻</a></li></ul></span>';
                            return val;
                        }else if (row[11] == 0) {
                            val = '<span class="dropDown"> <a class="dropDown_A powerButton 163" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">未入驻<i class="Hui-iconfont">&#xe6df;</i></a><ul class="dropDown-menu menu radius box-shadow"><li onclick="customer_yi(\'\',\'' + row[14] + '\')"><a href="#">已入驻</a></li></ul></span>';
                            return val;
                        }*/
                       if(row[11]==0){
                           val='未入驻'
                       }if(row[11]==20){
                            val='未入驻'
                        }else if(row[11]==30){
                           val='入驻云采'
                       }else if(row[11]==10){
                           val='入驻数采'
                       }
                       return val;
                    },
                    "targets": 12
                },
                {
                    "render": function (data, type, row, meta) {
                        //状态
                        var val = row[20]
                        if (val == 0) {
                            val = '启用'
                        }else if (val == 1) {
                            val = '禁用'
                        }
                        return val;
                    },
                    "targets": 13
                },
                {
                    "render": function (data, type, row, meta) {
                        if(row[5]==10 && row[16]==10){

                            var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_see.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a><span class="btn radius size-S mr-10" id="' + row[14] + '"  ';
                            return val;
                        }else if(row[5]==10 && row[16]==20){
                            var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_see.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a>';
                            return val;
                        }

                        if(row[5]==20 && row[16]==10){
                            if(row[17]==row[14] || row[17]==""){
                                var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_seeguanlian.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a><span class="btn radius size-S mr-10" id="' + row[14] + '"   ';
                                return val;
                            }else {
                                var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_see.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a><span class="btn radius size-S mr-10" id="' + row[14] + '"   ';
                                return val;
                            }


                        }else if(row[5]==20 && row[16]==20){
                            if(row[17]==row[14] || row[17]==""){
                                var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_seeguanlian.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a>';
                                return val;
                            }else {
                                var val = '<a class="powerButton 161" onclick="customerInfo(\'签约客户信息详情\',\'tomer_see.html?id=' + row[14] +'&customerId=' + row[0] + '\')">查看详情</a>';
                                return val;
                            }


                        }


                    },
                    "targets": 14
                },
            ]
        });
        //权限控制函数
        power()
    };
}
function customer_wei(obj,code) {
    console.log(code);
    layer.confirm('确认要未入驻吗？', function(index) {
        var spu_data = {
            customerCode: code,
            isEnter: 20,
        }
        var succCallBack = function(data, status, response) {
            if(data.errorCode == 0) {
                layer.msg("未入驻成功", {
                    icon: 6,
                    time: 1000
                }, function() {
                    getList(1)
                });

            }
        };
        return web.doAjax(root.inter.updateCustomerIsEnterByCode, 'post', spu_data, succCallBack);
    });

}
function customer_yi(obj,code) {
    console.log(code);
    layer.confirm('确认要已入驻吗？', function(index) {
        var spu_data = {
            customerCode: code,
            isEnter: 10,
        }
        var succCallBack = function(data, status, response) {
            if(data.errorCode == 0) {
                layer.msg("已入驻成功", {
                    icon: 6,
                    time: 1000
                }, function() {
                    getList(1)
                });

            }
        };
        return web.doAjax(root.inter.updateCustomerIsEnterByCode, 'post', spu_data, succCallBack);
    });

}


function getList(page_num) {
    console.log(crmCustomerIdOnearry)
    var customerGradeall = "";
    for (var i = 0; i < crmCustomerIdOnearry.length; i++) {
        customerGradeall += crmCustomerIdOnearry[i]+ ",";
    }
    //去掉最后一个逗号(如果不需要去掉，就不用写)
    if (customerGradeall.length > 0) {
        customerGradeall = customerGradeall.substr(0, customerGradeall.length - 1);
    }
    if($("#createTime").val()!=""&&$("#createTimeEnd").val()==""){
        $.Huimodalalert('请完善入驻时间',2000);
        return false;
    }else if($("#createTime").val()==""&&$("#createTimeEnd").val()!=""){
        $.Huimodalalert('请完善入驻时间',2000);
        return false;
    }
    var kehu_id = $("#kehu_id").val(),
        kehu_name = $("#kehu_name").val(),
        hetong = $("#hetong").val(),
       /* project = $("#project").val(),*/
        ascription_lsit = $("#ascription_lsit").val(),
        operate_manager = $("#operate_manager").text(),
        contract_state = $("#contract_state").val(),
        sale_manager = $("#sale_manager").text(),
        logmin = $("#logmin").val(),
        logmax = $("#logmax").val(),
        mnemonic = $("#mnemonic").val();
    var user_data = {

        customerId:kehu_id,
        customerName:kehu_name,
        belongGroupId:ascription_lsit,
       /* projectName:project,*/
        isEnter: $("#isEnter").val(),
        operateManagerId:operate_manager,
        belongSaleDirectorId:sale_manager,
        pageNum: page_num,
        pageSize: 50,
        customerType:$("#customerType").val(),
        customerGrade:customerGradeall,
        isRestrict:$("#isRestrict").val(),//限制发货
        limitType:$("#limitType").val(),
        warehouseCode:$("#shippingWarehouseno").val(),
       /* areaIds:sessionStorage.getItem("areaId"),//仓库权限串*/
        organizationIds:sessionStorage.getItem("companya"),//销售归属权限串
        salesSupervisorUserIds:sessionStorage.getItem("personnela"),//销售经理权限串
        startEnterTime:$("#createTime").val(),
        endEnterTime:$("#createTimeEnd").val(),
        "customerCode":$("#customerCode").val(),
        "forbidden":$("#forbidden").val()
    }
    var succCallBack = function (data, status, response) {
        sessionStorage.setItem("customerGrades","")
        if (data.errorCode == "0") {
            orderList(data);
            $('.M-box3').pagination({
                pageCount: data.list.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        type: "POST",
                        url:root.inter.querySignCustomerTable,
                        cache: false,  //禁用缓存
                        dataType: "json",
                        data: {

                            customerId:kehu_id,
                            customerName:kehu_name,
                            belongGroupId:ascription_lsit,
                            /*projectName:project,*/
                            isEnter: $("#isEnter").val(),
                            operateManagerId:operate_manager,
                            belongSaleDirectorId:sale_manager,
                            pageNum: api.getCurrent(),
                            pageSize: 50,
                            customerType:$("#customerType").val(),
                            customerGrade:customerGradeall,
                            isRestrict:$("#isRestrict").val(),//限制发货
                            limitType:$("#limitType").val(),
                            warehouseCode:$("#shippingWarehouseno").val(),
                            organizationIds:sessionStorage.getItem("companya"),//销售归属权限串
                            salesSupervisorUserIds:sessionStorage.getItem("personnela"),//销售经理权限串
                            startEnterTime:$("#createTime").val(),
                            endEnterTime:$("#createTimeEnd").val(),
                            "customerCode":$("#customerCode").val(),
                            "forbidden":$("#forbidden").val()
                        },
                        success: function (result) {
                            if(result.errorCode=="0"){
                                orderList(result);
                            }else {
                                layer.msg(result.errorMessage, {icon: 5,time:1000});
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });
        } else {
            var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
            dttable.fnClearTable(); //清空一下table
            return false
        }
    };
    web.doAjax(root.inter.querySignCustomerTable, 'post', user_data, succCallBack);


}
//运营经理弹框
var customerdata=sessionStorage.setItem("customerdata",customerdata);
function updataii(title,url,w,h) {
    layer_show(title,url+'?customerdata='+customerdata,w,h);

}
//修改邮箱
var index=0;
function updattt() {
    var cu = layer.confirm('<textarea id="remarksr" style="width:200px;height:100px;resize: none;" maxlength="60" placeholder="请输入邮箱" ></textarea>', {title:'提示',btn: ['确认', '取消']}, function(index){
        fini3()
        layer.close(cu);
    },function(){
        layer.close(cu);

    });
}
//第二个
function fini3(){
    var remarksr = $("#remarksr").val();
        $.ajax({
           /* root.inter.updateCustomerInfoByCode*/
            url:root.inter.updateCustomerInfoByCode,
            cache: false,  //禁用缓存
            type: "POST",
            dataType:'json',
            async:false,
            data: {
                customerCode:customerdata,
                operateManagerId:"",
                operateManagerName:"",
                groupBusinessLicenseAddr:"",
                groupOpeningAccountAddr:"",
                groupLoa:"",
                groupIDcardUrl:"",
                purchGoodIntroduct:"",
                email:remarksr
            },
            success: function (data) {
                location.replace(location.href)
            },
            error: function () {
                $.Huimodalalert('失败！',2000);
            }
        })

    layer.close(index);
}

//修改采购商品简述
var index=0;
function updatauuu(id,name) {
    var cu = layer.confirm('<textarea id="remarks" style="width:200px;height:100px;resize: none;" maxlength="60" placeholder="请输入采购商品简述" ></textarea>', {title:'提示',btn: ['确认', '取消']}, function(index){
        finish3(id,cu,name)
        var inv = $("#remarks").val();
        layer.close(cu);
    },function(){
        layer.close(cu);

    });
}
//第二个
function finish3(id,val){
    var remarks = $("#remarks").val();
    $.ajax({
        /* root.inter.updateCustomerInfoByCode*/
        url:root.inter.updateCustomerInfoByCode,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        async:false,
        data: {
            customerCode:customerdata,
            operateManagerId:"",
            operateManagerName:"",
            groupBusinessLicenseAddr:"",
            groupOpeningAccountAddr:"",
            groupLoa:"",
            groupIDcardUrl:"",
            purchGoodIntroduct:remarks,
            email:""
        },
        success: function (data) {
            location.replace(location.href)
        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    })

    layer.close(index);
}
//特殊关系导入
function upLoadFile() {
    $("#fileUp").trigger('click');
}
function putDataToPage() {
    var name=$("#fileUp").val()
    var result = /\.[^\.]+/.exec(name);
    if (result != ".xlsx" && result != ".xls") {
        $.Huimodalalert('类型错误仅支持EXCEL文档',2000);
        return false;
    }
    var formData = new FormData();
    formData.append('file', $("#fileUp")[0].files[0]);
    $.ajax({
        url: 'https://'+ window.location.host +'/api/admin/acontract/approval/importSpecialCustomerBO',
        cache: false,  //禁用缓存
        type: "POST",
        // 告诉jQuery不要去处理发送的数据
        processData: false,
        // 告诉jQuery不要去设置Content-Type请求头
        contentType: false,
        data: formData,
        success: function (data) {
            var datas=JSON.parse(data)
            $('#fileUp').val('');
            if(datas.errorCode==0){
                $.Huimodalalert('导入成功！',2000);
            }else {
                $.Huimodalalert(datas.msg,2000);
            }

        }
    });

}


//客户等级
var placeholder02html =[];//存放多选时的html
var placeholder02htmlinit =[];
var crmCustomerIdOnearry =[];//存放多选时的crmCustomerid
var spanhtml = '';
var crmCustomerIdOne='';
$(".ulbox").css('display','none');
/*点击 项目 显示下拉 选项,其中全选全不选，要做传值的处理*/
$(".dataval,.icon_arrow").on('click',function (e) {
    $(this).parent().children(".icon_arrow").toggleClass("icon_arrow_down");
    if($('.ulbox').css("display") == "none"){
        $('.ulbox').show();
        if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
            $(".placeholder02").html("")

        }
    }else{
        $(".ulbox").hide();
        if ($(".placeholder02").html()==""){
            $(".placeholder02").html('<span class="all-radius">全部</span>')
        }
    }
    /*------------------8.24 如果已经有选择过的--------------------*/
    var initcustomerId =[];
    placeholder02htmlinit=[]
    $.each($(".lidata"),function (index,itm) {

        initcustomerId.push($(itm).attr('crmCustomerId'))
        placeholder02htmlinit.push($(itm).attr('crmCustomername'))
    })
    if(crmCustomerIdOnearry.length >0){
        function isArray(str){
            return Object.prototype.toString.call(str) == "[object Array]";
        }
        if(isArray(crmCustomerIdOnearry)){
            crmCustomerIdOnearry= [crmCustomerIdOnearry].join().split(',');
        }else{
            crmCustomerIdOnearry= [crmCustomerIdOnearry].join().split(',');
        }
        console.log(crmCustomerIdOnearry)
        $.each($(".lidata"),function (index,itm) {
            $.each(crmCustomerIdOnearry,function (i,item) {
                $.each(initcustomerId,function (j,ite) {
                    if(item == ite){
                        if($("itm").attr('crmcustomerid')==item){
                            $(".lidata").find('.evetyipt').prop('checked',true);
                        }
                    }
                })
            })
        })

    }
    e.stopPropagation();
});
var checkednum=0;
//当点击下拉数据时 回显在input里面
var htmlspan='';
$(".ulbox").on('click','input.evetyipt',function (e) {
    if($(".placeholder02").find(".all-radius")&&$(".placeholder02").find(".all-radius").html()=="全部"){
        $(".placeholder02").html("")

    }
    e.stopPropagation();
    if($(this).prop('checked')){
        $(this).prop('checked',true);//选中
        checkednum ++;
        spanhtml=$(this).next().html();
        placeholder02html.push(spanhtml);
        crmCustomerIdOne = $(this).parent().attr('crmCustomerId');
        crmCustomerIdOnearry.push(crmCustomerIdOne);
        $.each(placeholder02html,function(i,item){
            htmlspan = '<span>'+item+'</span>'
        })
        $(".placeholder02").append(htmlspan);
        if($(".ulbox").find('input.evetyipt').length == checkednum){
            $(".checkboxall").prev().prop('checked',true);
        }
        //全选反选时会用
        if (checkednum==0) {
            $(".checkboxall").prev().prop('checked',true);

        }
        //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
        onenameadd()
    }else{
        checkednum --;
        $(this).prop('checked',false);
        var checkfalsehtml =  $(this).next().html();
        var tt =$(this).parent().attr('crmCustomerId');
        for (var i=0;i<crmCustomerIdOnearry.length;i++){
            if(crmCustomerIdOnearry[i] == tt){
                crmCustomerIdOnearry.splice(crmCustomerIdOnearry.indexOf(tt),1);
            }
        }
        var iptspandata = $('.placeholder02 span');//点击选中回显在span 里面的值
        $.each(iptspandata,function (i,item) {
            if($(item).html() == checkfalsehtml){
                $(item).html('');
                $(item).remove();
            }
        });
        placeholder02html.splice($(this).next().html(),1);
        if($(".ulbox").find('input.evetyipt').length != checkednum){
            $(".checkboxall").prev().prop('checked',false);
        }
        onename();
    }
});
//可点击空白处
$(document).click(function() {
    $(".ulbox").css('display','none');
    if ($(".placeholder02").html()==""){
        $(".placeholder02").html('<span class="all-radius">全部</span>')
    }
});
function onenameadd(){
    //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
    if(crmCustomerIdOnearry.length == 1){
        $(".placeholder02 span").css('max-width','none');
        $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
    }else{
        $(".placeholder02 span").css('max-width','48px');
    }
}
function onename(){
    //判断如果只选择了一个下拉选项 在input 里面应该展示全部的名称
    if(crmCustomerIdOnearry.length == 1){
        $(".placeholder02 span").css('max-width','none');
        $(".placeholder02 span").attr('title',$(".placeholder02 span").html());
    }
}

/*点击全选 联动 传值*/
var ulboxli = $(".ulbox").find('li');
$(".checkboxall").parent().on('click','input',function (e) {
    e.stopPropagation();
    if($(this).prop('checked')){//全选
        $(this).prop('checked',true);
        ulboxli.find('input').prop('checked',true);
        $(".placeholder02").html("")
        placeholder02html =placeholder02htmlinit;
        var htmlspan='';
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        var crmCustomerIds=$(this).attr('crmCustomerId')
        crmCustomerIdOnearry=crmCustomerIds.split(",")
        $(".placeholder02").append(htmlspan);
    }else{//全不选
        $(this).prop('checked',false);
        ulboxli.find('input').prop('checked',false);
        crmCustomerIdOnearry=[];
        placeholder02html=[];
        $(".placeholder02").html('');
    }
});
$(".ulbox").on('click','.checkboxall',function (e) {
    e.stopPropagation();
    if(  $(this).parent().find('input').prop('checked') == false){//全选
        $(this).parent().find('input').prop('checked',true);
        ulboxli.find('input').prop('checked',true);
        placeholder02html =placeholder02htmlinit;
        var htmlspan='';
        $.each(placeholder02html,function(i,item){
            htmlspan += '<span>'+item+'</span>'
        });
        $(".placeholder02").append(htmlspan);
    }else{//全不选
        $(this).parent().find('input').prop('checked',false);
        ulboxli.find('input').prop('checked',false);
        crmCustomerIdOnearry=[];
        placeholder02html=[];
        $(".placeholder02").html('');
    }
})
//重置
function resetbtn() {
    console.log(crmCustomerIdOnearry)
    crmCustomerIdOnearry=[];
    placeholder02html=[];
    $(".placeholder02").html("");
}

//事项提示弹框跳转
var customerisEnter= sessionStorage.getItem("customerisEnter")//入驻状态
var customerGrades= sessionStorage.getItem("customerGrades")//客户等级
if(customerGrades){
    var htmlarrs="S级别,A级别,B级别,C级别"
    crmCustomerIdOnearry=[]
    crmCustomerIdOnearry=customerGrades.split(",")
    placeholder02html=htmlarrs.split(",")
    var htmlspan3=""
    $.each(placeholder02html,function(i,item){
        htmlspan3 += '<span>'+item+'</span>'
    });
    $(".placeholder02").html(htmlspan3);
    $(".ulbox").find('input.evetyipt')[0].checked=true
    $(".ulbox").find('input.evetyipt')[1].checked=true
    $(".ulbox").find('input.evetyipt')[2].checked=true
    $(".ulbox").find('input.evetyipt')[3].checked=true
    checkednum=4
    $("#isEnter").val(customerisEnter)
    getList(1)

}
